package com.hsy.linemoney.modules.my.mydeals;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.deparse.dpframe.ui.android.widget.adapter.DPBaseAdapter;
import com.hsy.linemoney.R;
import com.hsy.linemoney.apiservice.MyDealService;

import java.util.List;

/**
 * Created by MartinKent on 2016/10/24.
 */

public abstract class MyDealListAdapter<T> extends DPBaseAdapter<T> {
    public MyDealListAdapter(Context context) {
        super(context);
    }

    public MyDealListAdapter(Context context, List<T> data) {
        super(context, data);
    }

    @Override
    public CommonBaseViewHolder<T> getHolder(int i) {
        return new ViewHolder();
    }

    public abstract int getType(int position);

    private class ViewHolder extends DPBaseAdapter.CommonBaseViewHolder<T> {
        View listIcon;
        TextView orderSn;
        TextView pubTime;
        TextView waitMoney;
        TextView exchangeRate;
        TextView expectedMoney;
        TextView dealTime;
        private View dealTimeContainer;

        @Override
        public View create(int i) {
            View convertView = LayoutInflater.from(context).inflate(R.layout.deal_list_item, null);

            listIcon = (View) convertView.findViewById(R.id.list_icon);
            orderSn = (TextView) convertView.findViewById(R.id.order_sn);
            pubTime = (TextView) convertView.findViewById(R.id.pub_time);
            waitMoney = (TextView) convertView.findViewById(R.id.wait_money);
            exchangeRate = (TextView) convertView.findViewById(R.id.exchange_rate);
            expectedMoney = (TextView) convertView.findViewById(R.id.expected_money);
            dealTime = (TextView) convertView.findViewById(R.id.deal_time);
            dealTimeContainer = convertView.findViewById(R.id.deal_time_container);
            return convertView;
        }

        @Override
        public void update(int i, T myDealBean) {
            listIcon.setVisibility(View.GONE);
            orderSn.setVisibility(View.GONE);
            int type = getType(i);
            if (type == MyDealBean.PART_DEALED) {
                dealTimeContainer.setVisibility(View.VISIBLE);
            } else if (type == MyDealBean.WAIT_DEAL) {
                dealTimeContainer.setVisibility(View.GONE);
            }

        }

    }
}
